package com.bestom.bluetoothlock.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;


import com.bestom.bluetoothlock.R;
import com.bestom.bluetoothlock.entity.DeviceInfo;
import com.bestom.bluetoothlock.util.CurrencyDataManage;

import java.util.ArrayList;
import java.util.List;

public class DeviceListAdapter extends BaseAdapter {
    private List<DeviceInfo> list = new ArrayList();
    private Context mContext;

    public long getItemId(int i) {
        return (long) i;
    }

    public DeviceListAdapter(Context context) {
        this.mContext = context;
    }

    public void setData(List<DeviceInfo> list2) {
        this.list = list2;
        notifyDataSetChanged();
    }

    public List<DeviceInfo> getList() {
        return this.list;
    }

    public int getCount() {
        return this.list.size();
    }

    public Object getItem(int i) {
        return this.list.get(i);
    }

    public View getView(int i, View view, ViewGroup viewGroup) {
        View view2;
        ViewHolder viewHolder;
        if (view == null) {
            viewHolder = new ViewHolder();
            view2 = LayoutInflater.from(this.mContext).inflate(R.layout.device_list_item, (ViewGroup) null);
            viewHolder.ll_item = (RelativeLayout) view2.findViewById(R.id.ll_item);
            viewHolder.tv_device_name = (TextView) view2.findViewById(R.id.tv_device_name);
            viewHolder.tv_device_address = (TextView) view2.findViewById(R.id.tv_device_address);
            viewHolder.tv_device_state = (TextView) view2.findViewById(R.id.tv_device_state);
            view2.setTag(viewHolder);
        } else {
            view2 = view;
            viewHolder = (ViewHolder) view.getTag();
        }
        viewHolder.tv_device_name.setText(this.list.get(i).getNickname());
        viewHolder.tv_device_address.setText(this.list.get(i).getLockmac());
        DeviceInfo currentBleDevice = CurrencyDataManage.getInstance().getCurrentBleDevice();
        if (currentBleDevice.getLockmac().equals(this.list.get(i).getLockmac())) {
            viewHolder.tv_device_state.setVisibility(View.VISIBLE);
        } else {
            viewHolder.tv_device_state.setVisibility(View.GONE);
        }
        return view2;
    }

    public final class ViewHolder {
        RelativeLayout ll_item;
        TextView tv_device_address;
        TextView tv_device_name;
        TextView tv_device_state;

        public ViewHolder() {
        }
    }
}
